Add filter_by_search_query support to get_movies, get_episodes and get_tv_shows.#21
Add filter_by_search_query support to get_movies, get_episodes and get_tv_shows.#21anishsane wants to merge 1 commit into
Conversation
| @staticmethod | ||
| def _filter_by_search_query(original_result, search_query=None, result_type=None, score_cutoff=100): |
There was a problem hiding this comment.
Any reason we use a static method here as opposed to a separate method?
There was a problem hiding this comment.
I also prefer having a separate search method unless there's a good reason to go this route.
There was a problem hiding this comment.
It is a helper function. Hence prefixed by an _
I wanted to keep it under the Kodi class. So, not declared it as a global function.
But it did not need the self parameter. So, marked it as a static function.
If you prefer, I can make it a regular function and ignore the self parameter.
It will look like
- def _filter_by_search_query(original_result, search_query=None, result_type=None, score_cutoff=100):
+ def _filter_by_search_query(self, original_result, search_query=None, result_type=None, score_cutoff=100):
# .... existing code here
...
...
- return Kodi._filter_by_search_query(results, search_query, 'movies', score_cutoff)
+ return self._filter_by_search_query(results, search_query, 'movies', score_cutoff)
# etc
There was a problem hiding this comment.
I have updated the code as per your suggestion. Let me know if this is better.
There was a problem hiding this comment.
I think you missed the point. It's not about making this non-static (as you correctly mentioned, it doesn't use self), but rather adding a new, non-static, method, for search, rather than piggybacking on the existing ones.
There was a problem hiding this comment.
I have updated the PR. Replaced my earlier logic entirely. Please take a look.
This function takes 2 arguments: media_type and search_query. Currently media_type can take the value 'movies', 'tvshows' or 'episodes'. (The logic can be extended later.) The results of the corresponding get_*<media type> are filtered against the search query by a fuzzy match logic. This functionality will be used by Home Assistant for the 'Search and play' intent. In addition to search_query, the user can also provide a parameter score_cutoff % (defaults to 80%) to be used as a threshold for fuzzy filtering.
When calling these functions, the user can supply the optional string parameter - search_query.
If this parameter is provided, the results are filtered against the search_query parameter using a fuzzy search. This functionality will be used by Home Assistant for 'Search and Play' intent.
In addition to search_query, the user can also provide a parameter score_cutoff % (defaults to 80%) to be used as a threshold for fuzzy filtering.